package com.leyou.item.service.controller;

import com.leyou.common.bean.PageResult;
import com.leyou.common.bean.Result;
import com.leyou.item.inter.dto.BrandPageDTO;
import com.leyou.item.inter.dto.BrandUpdateDTO;
import com.leyou.item.inter.pojo.Brand;
import com.leyou.item.service.mapper.BrandMapper;
import com.leyou.item.service.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author zqq
 * @ClassName BrandController
 * @Description: 品牌接口
 * @date 2020/3/5-9:10
 */
@Api(value = "BrandController",description = "品牌接口")
@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @PostMapping("page")
    @ApiOperation(value = "根据查询条件分页并排序查询品牌信息", notes = "根据查询条件分页并排序查询品牌信息")
    public Result<PageResult<Brand>> queryBrandsByPage(@RequestBody BrandPageDTO dto){
        return  this.brandService.queryBrandsByPage(dto);
    }

    @PostMapping("update")
    @ApiOperation(value = "新增品牌", notes = "新增品牌")
    public Result saveBrand(BrandUpdateDTO dto,@RequestParam("cids") List<Long> cids){
        return this.brandService.updateBrand(dto,cids);
    }

    @PutMapping("update")
    @ApiOperation(value = "修改品牌", notes = "修改品牌")
    public Result updateBrand(BrandUpdateDTO dto,@RequestParam("cids") List<Long> cids){
        return this.brandService.updateBrand(dto,cids);
    }

    @GetMapping("cid/{cid}")
    @ApiOperation(value = "根据商品分类id，查询对应品牌", notes = "根据商品分类id，查询对应品牌")
    public Result<List<Brand>> queryBrandsByCid(@ApiParam(name = "cid",value = "商品分类id",required = true) @PathVariable("cid")Long cid){
        return this.brandService.queryBrandsByCid(cid);
    }

    @GetMapping("bid/{bid}")
    @ApiOperation(value = "根据品牌id,查询对应品牌", notes = "根据品牌id,查询对应品牌")
    public Result<Brand> queryBrandById(@ApiParam(name = "bid",value = "品牌id",required = true) @PathVariable("bid")Long bid){
        return this.brandService.queryBrandById(bid);
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除品牌", notes = "删除品牌")
    public Result deleteBrand(@ApiParam(name = "id",value = "品牌id",required = true) @PathVariable("id") Long id){
        return this.brandService.deleteBrand(id);
    }
}
